﻿
using Dapper;
using HBase;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
namespace hCommand
{
    /**
   *┌────────────────────────────────────────────────┐
   *│　描    述：Component                                                    
   *│　作    者：sgj                                              
   *│　版    本：1.0                                              
   *│　创建时间：2020/9/2 11:28:16                        
   *└────────────────────────────────────────────────┘
   **/
    public class Continue99999Engine<CS> : AbsTaskCSEngine where CS : AbsCoreStock
    {
        public long paramId;

        protected override StockStatus change2Status()
        {
            return StockStatus.移库中;
        }

        protected override TransRes Execute( )
        {
            CoreTaskParam ctp = getById<CoreTaskParam>(paramId);
            if (ctp == null)
            {
                return new TransRes("任务不存在");
            }
            if (ctp.des != TaskNoUtil.virtual_Loc)
            {
                return new TransRes("目标异常");
            }
            if (ctp.status > (int)CoreTaskParamStatus.执行结束)
            {
                return new TransRes("任务已经结束");
            }
            List<CoreTaskParam> ctpList = query<CoreTaskParam>("select * from Core_Task_Param  where task_Id=@taskId and src=@src and id<>@id", ctp);

            if (ctpList.Count > 0)
            {
                return new TransRes("已经生成实际任务");
            }
            CoreTask ct = getById<CoreTask>(ctp.taskId);
            CS cs = getById<CS>(ct.stockId);
            if (cs.id == 0)
            {
                return new TransRes("stock 为空");
            }
            CoreWhLoc whLoc = getById<CoreWhLoc>(ctp.src );
            List<CoreWhLoc> locList = getLoc4SelectIn(whLoc.areaId, whLoc.moveGroup);

            CoreWhLoc loc = I18nConfig.select(locList, cs.deepDiff, cs);
            if (loc == null)
            {
                return new TransRes("货位获取异常");

            }
            long paramTaskId = moveCoreTaskParam( ct.id, ctp.src, (int)loc.id);

            LocCoreUtil.UpdataWhLoc(this,(int)loc.id, ct.goodDiff);

            return new TransRes();
        }

    }
}
